package com.tiecode.pastejava;

import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.util.TreeScanner;

public class JavaMethodReplacer extends TreeScanner<Void, Void> {
    private String result;
    private int printlnLevel = 0;

    public String getResult() {
        return result;
    }

    @Override
    public Void visitMethodInvocation(MethodInvocationTree node, Void unused) {
        scan(node.getMethodSelect(), null);
        return null;
    }

    @Override
    public Void visitMemberSelect(MemberSelectTree node, Void unused) {
        if (printlnLevel == 0 && node.getIdentifier().contentEquals("println")) {
            printlnLevel++;
            scan(node.getExpression(), null);
        } else if (printlnLevel == 1 && node.getIdentifier().contentEquals("out")) {
            printlnLevel++;
            result = "调试输出";
        }
        return null;
    }
}
